# ESC功能切换代码

# 1.按下不抬起：暂停监听；松开ESC继续监听
def on_press(key):
    global paused
    try:
        if key == keyboard.Key.esc:
            paused = True  # 按下 Esc 键时暂停监听
        else:
            if not paused:
                operation_info.append((f'Key pressed: {key.char}', None))
    except AttributeError:
        if not paused:
            operation_info.append((f'Key pressed: {key}', None))

def on_release(key):
    global paused
    if key == keyboard.Key.esc:
        paused = False  # 释放 Esc 键时恢复监听
        operation_info.append(('Esc key released', None))

# 2.按下并抬起1次ESC停止监听，再按下并抬起1次恢复监听状态
def on_press(key):
    global paused
    try:
        if key == keyboard.Key.esc:
            paused = not paused  # 按下 Esc 键时暂停/恢复监听
        else:
            if not paused:
                operation_info.append((f'Key pressed: {key.char}', None))
    except AttributeError:
        if not paused:
            operation_info.append((f'Key pressed: {key}', None))

def on_release(key):
    if key == keyboard.Key.esc and not paused:
        operation_info.append(('Esc key released', None))